const config  = require('./config.js')[process.env.RUN_CONF];
const http = require("http");
const log = require("./log.js");
var dbFun = {};
dbFun.query = ()=>{
  return new Promise(( resolve, reject ) => {
          var opt = {
            // hostname:'127.0.0.1',
            hostname:'boxuntech.cn',
            port:'80',
            path:'/activity/'+config.tt+'/s.php?action=userListDownload',
            method: 'GET'
          };

          http.get(opt,res=>{
            log('STATUS: ' + res.statusCode); 
            log('HEADERS: ' + JSON.stringify(res.headers)); 
            res.setEncoding('utf8'); 
            var pageData = '';
                res.on('error', function (errget) {
                       //出错处理
                      log(errget,'error');  
                      reject(errget);
                });
                res.on('data', function (chunk) {
                       pageData += chunk;
                       // info(chunk)
                });

                res.on('end', function(){
                      //console.dir(pageData);
                      // var content = pageData;//获取到网页内容
                      // var hrefs=getAHref(content);//获取链接
                      var j=0;
                      try{
                          j = JSON.parse(pageData);
                      }catch(e){
                        log('获取用户数据格式异常,data:','error');
                        log(pageData,'error');
                        log(e,'error');
                      }
                      resolve(j);
                });
          })
  })
}
module.exports = dbFun; 